package com.wlz.controller;

import com.wlz.basic.SpringProducer;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wlz
 * @date 2022-07-03  3:14 下午
 */
@RestController
@RequestMapping("/MQTest")
public class MQTestController {

    private final String topic = "TestTopic";

    @Autowired
    private SpringProducer springProducer;

    @ApiOperation(value = "sendMessage发送接口",  notes = "简单发送消息")
    @GetMapping("/sendMessage")
    public String sendMessage(String message) {
        springProducer.sendMessage(topic, message);
        return "消息发送完毕";
    }


    @ApiOperation(value = "sendTransactionMessage发送接口",  notes = "事务消息")
    @GetMapping("/sendTransactionMessage")
    public String sendTransactionMessage(String message) throws Exception{
        springProducer.sendMessageInTransaction(topic, message);
        return "消息发送完毕";
    }

}
